import $service from '../../../../service.js';
var checklist_id;
var user_type = "1";
var user_id;
var imgurl;
Page({
    data:{
       active : true,
       checklistMap:{},
       inquiryMap:{},
       doctorMap:{},
       checklist_imgurl:''
       
    },
    onLoad(e){
        checklist_id = e.checklist_id
    },
    onShow() {
        if(!$service.isUndefinedAndEmpty($service.getUserLocalStorage().user_type)){
        		user_type = $service.getUserLocalStorage().user_type;
        	}
         if(user_type == 1){//1用户 1门店
             user_id = $service.getUserLocalStorage().user_id;
         }else{
             user_id = $service.getUserLocalStorage().store_id;
         }
        this.publicUtil_getInquiryLogPrescriptionDetails()
    },
    publicUtil_getInquiryLogPrescriptionDetails:function(){
        var this_ = this;
        var jsonData ={
            "checklist_id" : checklist_id
        }
        var jsonAjax = {
            "url": "publicUtil_getInquiryLogChecklistDetails.do",
            "jsonData": jsonData,
        }
        $service.getAjaxData(jsonAjax, this.getInquiryLogChecklistDetails_back);
    },
    getInquiryLogChecklistDetails_back:function(jsonBack){
        var data=$service.strToJson(jsonBack.data).data;
        var doctorMap = data.doctorMap;
        var checklistMap = data.checklistMap;////处方内容
        checklistMap.imgurl ='/' + checklistMap.imgurl
        imgurl = $service.getUserImgPub(checklistMap.imgurl)
        var checklistDetailsList = checklistMap.checklistDetailsList;//处方
        var inquiryMap = data.inquiryMap;//诊断信息
        inquiryMap.lrsj = $service.nothinglrsj(inquiryMap.lrsj)
        this.setData({
            checklistMap:checklistMap,
            doctorMap:doctorMap,
            inquiryMap:inquiryMap,
            checklist_imgurl: imgurl
        })
    },
    previewImage: function(e) { //图片放大
        var index = e.currentTarget.dataset.index;
        var num = e.currentTarget.dataset.num;
        
        var all = [];
        all.push(this.data.checklist_imgurl);
        all.forEach(item => {
          item = item.replace(/https/, 'http')
        })
        wx.previewImage({
            urls: all
        })
    },
    checklistMapTap(e){
        console.log(e)
        var num = e.currentTarget.dataset.num;
        if(num == 1){
            var imgSrc = imgurl;
             if(!$service.isUndefinedAndEmpty(imgurl)){
                 wx.downloadFile({
                   url: imgSrc,
                   success: function (res) {
                     console.log(res);
                     //图片保存到本地
                     wx.saveImageToPhotosAlbum({
                       filePath: res.tempFilePath,
                       success: function (data) {
                         wx.showToast({
                           title: '保存成功',
                           icon: 'success',
                           duration: 2000
                         })
                       },
                       fail: function (err) {
                         console.log(err);
                         if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
                           console.log("当初用户拒绝，再次发起授权")
                           wx.openSetting({
                             success(settingdata) {
                               console.log(settingdata)
                               if (settingdata.authSetting['scope.writePhotosAlbum']) {
                                 console.log('获取权限成功，给出再次点击图片保存到相册的提示。')
                               } else {
                                 console.log('获取权限失败，给出不给权限就无法正常使用的提示')
                               }
                             }
                           })
                         }
                       },
                       complete(res){
                         console.log(res);
                       }
                     })
                   }
                 })
            }else{
                $service.showToast('未生成成功')
            }
        }else{
            wx.navigateBack({
                delta:1
            })
        }
       
            
    }
})